home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / sprite / valops.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  33.9 KB  |  1,278 lines

  1. /* Perform non-arithmetic operations on values, for GDB.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "stdio.h"
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "symtab.h"
  24. #include "value.h"
  25. #include "frame.h"
  26. #include "inferior.h"
  27.  
  28. /* Cast value ARG2 to type TYPE and return as a value.
  29.    More general than a C cast: accepts any two types of the same length,
  30.    and if ARG2 is an lvalue it can be cast into anything at all.  */
  31.  
  32. value
  33. value_cast (type, arg2)
  34.      struct type *type;
  35.      register value arg2;
  36. {
  37.   register enum type_code code1;
  38.   register enum type_code code2;
  39.   register int scalar;
  40.  
  41.   /* Coerce arrays but not enums.  Enums will work as-is
  42.      and coercing them would cause an infinite recursion.  */
  43.   if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM)
  44.     COERCE_ARRAY (arg2);
  45.  
  46.   code1 = TYPE_CODE (type);
  47.   code2 = TYPE_CODE (VALUE_TYPE (arg2));
  48.   scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
  49.         || code2 == TYPE_CODE_ENUM);
  50.  
  51.   if (code1 == TYPE_CODE_FLT && scalar)
  52.     return value_from_double (type, value_as_double (arg2));
  53.   else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
  54.        && (scalar || code2 == TYPE_CODE_PTR))
  55.     return value_from_long (type, value_as_long (arg2));
  56.   else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
  57.     {
  58.       VALUE_TYPE (arg2) = type;
  59.       return arg2;
  60.     }
  61.   else if (VALUE_LVAL (arg2) == lval_memory)
  62.     {
  63.       return value_at (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
  64.     }
  65.   else
  66.     error ("Invalid cast.");
  67. }
  68.  
  69. /* Create a value of type TYPE that is zero, and return it.  */
  70.  
  71. value
  72. value_zero (type, lv)
  73.      struct type *type;
  74.      enum lval_type lv;
  75. {
  76.   register value val = allocate_value (type);
  77.  
  78.   bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type));
  79.   VALUE_LVAL (val) = lv;
  80.  
  81.   return val;
  82. }
  83.  
  84. /* Return the value with a specified type located at specified address.  */
  85.  
  86. value
  87. value_at (type, addr)
  88.      struct type *type;
  89.      CORE_ADDR addr;
  90. {
  91.   register value val = allocate_value (type);
  92.   int temp;
  93.  
  94.   temp = read_memory (addr, VALUE_CONTENTS (val), TYPE_LENGTH (type));
  95.   if (temp)
  96.     {
  97.       if (have_inferior_p ())
  98.     print_sys_errmsg ("ptrace", temp);
  99.       /* Actually, address between addr and addr + len was out of bounds. */
  100.       error ("Cannot read memory: address 0x%x out of bounds.", addr);
  101.     }
  102.  
  103.   VALUE_LVAL (val) = lval_memory;
  104.   VALUE_ADDRESS (val) = addr;
  105.  
  106.   return val;
  107. }
  108.  
  109. /* Store the contents of FROMVAL into the location of TOVAL.
  110.    Return a new value with the location of TOVAL and contents of FROMVAL.  */
  111.  
  112. value
  113. value_assign (toval, fromval)
  114.      register value toval, fromval;
  115. {
  116.   register struct type *type = VALUE_TYPE (toval);
  117.   register value val;
  118.   char raw_buffer[MAX_REGISTER_RAW_SIZE];
  119.   char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
  120.   int use_buffer = 0;
  121.  
  122.   extern CORE_ADDR find_saved_register ();
  123.  
  124.   COERCE_ARRAY (fromval);
  125.  
  126.   if (VALUE_LVAL (toval) != lval_internalvar)
  127.     fromval = value_cast (type, fromval);
  128.  
  129.   /* If TOVAL is a special machine register requiring conversion
  130.      of program values to a special raw format,
  131.      convert FROMVAL's contents now, with result in `raw_buffer',
  132.      and set USE_BUFFER to the number of bytes to write.  */
  133.  
  134.   if (VALUE_REGNO (toval) >= 0
  135.       && REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
  136.     {
  137.       int regno = VALUE_REGNO (toval);
  138.       if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno))
  139.     fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval);
  140.       bcopy (VALUE_CONTENTS (fromval), virtual_buffer,
  141.          REGISTER_VIRTUAL_SIZE (regno));
  142.       REGISTER_CONVERT_TO_RAW (regno, virtual_buffer, raw_buffer);
  143.       use_buffer = REGISTER_RAW_SIZE (regno);
  144.     }
  145.  
  146.   switch (VALUE_LVAL (toval))
  147.     {
  148.     case lval_internalvar:
  149.       set_internalvar (VALUE_INTERNALVAR (toval), fromval);
  150.       break;
  151.  
  152.     case lval_internalvar_component:
  153.       set_internalvar_component (VALUE_INTERNALVAR (toval),
  154.                  VALUE_OFFSET (toval),
  155.                  VALUE_BITPOS (toval),
  156.                  VALUE_BITSIZE (toval),
  157.                  fromval);
  158.       break;
  159.  
  160.     case lval_memory:
  161.       if (VALUE_BITSIZE (toval))
  162.     {
  163.       int val;
  164.       read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  165.                &val, sizeof val);
  166.       modify_field (&val, (int) value_as_long (fromval),
  167.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  168.       write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  169.             &val, sizeof val);
  170.     }
  171.       else if (use_buffer)
  172.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  173.               raw_buffer, use_buffer);
  174.       else
  175.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  176.               VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  177.       break;
  178.  
  179.     case lval_register:
  180.       if (VALUE_BITSIZE (toval))
  181.     {
  182.       int val;
  183.  
  184.       read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  185.                    &val, sizeof val);
  186.       modify_field (&val, (int) value_as_long (fromval),
  187.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  188.       write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  189.                 &val, sizeof val);
  190.     }
  191.       else if (use_buffer)
  192.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  193.                   raw_buffer, use_buffer);
  194.       else
  195.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  196.                   VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  197.       break;
  198.  
  199.     case lval_reg_frame_relative:
  200.       {
  201.     /* value is stored in a series of registers in the frame
  202.        specified by the structure.  Copy that value out, modify
  203.        it, and copy it back in.  */
  204.     int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type));
  205.     int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval));
  206.     int byte_offset = VALUE_OFFSET (toval) % reg_size;
  207.     int reg_offset = VALUE_OFFSET (toval) / reg_size;
  208.     int amount_copied;
  209.     char *buffer = (char *) alloca (amount_to_copy);
  210.     int regno;
  211.     FRAME frame;
  212.     CORE_ADDR addr;
  213.  
  214.     /* Figure out which frame this is in currently.  */
  215.     for (frame = get_current_frame ();
  216.          frame && FRAME_FP (frame) != VALUE_FRAME (toval);
  217.          frame = get_prev_frame (frame))
  218.       ;
  219.  
  220.     if (!frame)
  221.       error ("Value being assigned to is no longer active.");
  222.  
  223.     amount_to_copy += (reg_size - amount_to_copy % reg_size);
  224.  
  225.     /* Copy it out.  */
  226.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  227.           amount_copied = 0);
  228.          amount_copied < amount_to_copy;
  229.          amount_copied += reg_size, regno++)
  230.       {
  231.         addr = find_saved_register (frame, regno);
  232.         if (addr == 0)
  233.           read_register_bytes (REGISTER_BYTE (regno),
  234.                    buffer + amount_copied,
  235.                    reg_size);
  236.         else
  237.           read_memory (addr, buffer + amount_copied, reg_size);
  238.       }
  239.  
  240.     /* Modify what needs to be modified.  */
  241.     if (VALUE_BITSIZE (toval))
  242.       modify_field (buffer + byte_offset,
  243.             (int) value_as_long (fromval),
  244.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  245.     else if (use_buffer)
  246.       bcopy (raw_buffer, buffer + byte_offset, use_buffer);
  247.     else
  248.       bcopy (VALUE_CONTENTS (fromval), buffer + byte_offset,
  249.          TYPE_LENGTH (type));
  250.  
  251.     /* Copy it back.  */
  252.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  253.           amount_copied = 0);
  254.          amount_copied < amount_to_copy;
  255.          amount_copied += reg_size, regno++)
  256.       {
  257.         addr = find_saved_register (frame, regno);
  258.         if (addr == 0)
  259.           write_register_bytes (REGISTER_BYTE (regno),
  260.                     buffer + amount_copied,
  261.                     reg_size);
  262.         else
  263.           write_memory (addr, buffer + amount_copied, reg_size);
  264.       }
  265.       }
  266.       break;
  267.     
  268.  
  269.     default:
  270.       error ("Left side of = operation is not an lvalue.");
  271.     }
  272.  
  273.   /* Return a value just like TOVAL except with the contents of FROMVAL
  274.      (except in the case of the type if TOVAL is an internalvar).  */
  275.  
  276.   if (VALUE_LVAL (toval) == lval_internalvar
  277.       || VALUE_LVAL (toval) == lval_internalvar_component)
  278.     {
  279.       type = VALUE_TYPE (fromval);
  280.     }
  281.  
  282.   val = allocate_value (type);
  283.   bcopy (toval, val, VALUE_CONTENTS (val) - (char *) val);
  284.   bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS (val), TYPE_LENGTH (type));
  285.   VALUE_TYPE (val) = type;
  286.   
  287.   return val;
  288. }
  289.  
  290. /* Extend a value VAL to COUNT repetitions of its type.  */
  291.  
  292. value
  293. value_repeat (arg1, count)
  294.      value arg1;
  295.      int count;
  296. {
  297.   register value val;
  298.  
  299.   if (VALUE_LVAL (arg1) != lval_memory)
  300.     error ("Only values in memory can be extended with '@'.");
  301.   if (count < 1)
  302.     error ("Invalid number %d of repetitions.", count);
  303.  
  304.   val = allocate_repeat_value (VALUE_TYPE (arg1), count);
  305.  
  306.   read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
  307.            VALUE_CONTENTS (val),
  308.            TYPE_LENGTH (VALUE_TYPE (val)) * count);
  309.   VALUE_LVAL (val) = lval_memory;
  310.   VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
  311.  
  312.   return val;
  313. }
  314.  
  315. value
  316. value_of_variable (var)
  317.      struct symbol *var;
  318. {
  319.   return read_var_value (var, (FRAME) 0);
  320. }
  321.  
  322. /* Given a value which is an array, return a value which is
  323.    a pointer to its first element.  */
  324.  
  325. value
  326. value_coerce_array (arg1)
  327.      value arg1;
  328. {
  329.   register struct type *type;
  330.   register value val;
  331.  
  332.   if (VALUE_LVAL (arg1) != lval_memory)
  333.     error ("Attempt to take address of value not located in memory.");
  334.  
  335.   /* Get type of elements.  */
  336.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
  337.     type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  338.   else
  339.     /* A phony array made by value_repeat.
  340.        Its type is the type of the elements, not an array type.  */
  341.     type = VALUE_TYPE (arg1);
  342.  
  343.   /* Get the type of the result.  */
  344.   type = lookup_pointer_type (type);
  345.   val = value_from_long (builtin_type_long,
  346.                (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  347.   VALUE_TYPE (val) = type;
  348.   return val;
  349. }
  350.  
  351. /* Return a pointer value for the object for which ARG1 is the contents.  */
  352.  
  353. value
  354. value_addr (arg1)
  355.      value arg1;
  356. {
  357.   register struct type *type;
  358.   register value val, arg1_coerced;
  359.  
  360.   /* Taking the address of an array is really a no-op
  361.      once the array is coerced to a pointer to its first element.  */
  362.   arg1_coerced = arg1;
  363.   COERCE_ARRAY (arg1_coerced);
  364.   if (arg1 != arg1_coerced)
  365.     return arg1_coerced;
  366.  
  367.   if (VALUE_LVAL (arg1) != lval_memory)
  368.     error ("Attempt to take address of value not located in memory.");
  369.  
  370.   /* Get the type of the result.  */
  371.   type = lookup_pointer_type (VALUE_TYPE (arg1));
  372.   val = value_from_long (builtin_type_long,
  373.         (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  374.   VALUE_TYPE (val) = type;
  375.   return val;
  376. }
  377.  
  378. /* Given a value of a pointer type, apply the C unary * operator to it.  */
  379.  
  380. value
  381. value_ind (arg1)
  382.      value arg1;
  383. {
  384.   /* Must do this before COERCE_ARRAY, otherwise an infinite loop
  385.      will result */
  386.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  387.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  388.              (CORE_ADDR) value_as_long (arg1));
  389.  
  390.   COERCE_ARRAY (arg1);
  391.  
  392.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_MEMBER)
  393.     error ("not implemented: member types in value_ind");
  394.  
  395.   /* Allow * on an integer so we can cast it to whatever we want.
  396.      This returns an int, which seems like the most C-like thing
  397.      to do.  "long long" variables are rare enough that
  398.      BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
  399.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
  400.     return value_at (builtin_type_int,
  401.              (CORE_ADDR) value_as_long (arg1));
  402.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
  403.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  404.              (CORE_ADDR) value_as_long (arg1));
  405.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  406.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  407.              (CORE_ADDR) value_as_long (arg1));
  408.   error ("Attempt to take contents of a non-pointer value.");
  409. }
  410.  
  411. /* Pushing small parts of stack frames.  */
  412.  
  413. /* Push one word (the size of object that a register holds).  */
  414.  
  415. CORE_ADDR
  416. push_word (sp, buffer)
  417.      CORE_ADDR sp;
  418.      REGISTER_TYPE buffer;
  419. {
  420.   register int len = sizeof (REGISTER_TYPE);
  421.  
  422. #if 1 INNER_THAN 2
  423.   sp -= len;
  424.   write_memory (sp, &buffer, len);
  425. #else /* stack grows upward */
  426.   write_memory (sp, &buffer, len);
  427.   sp += len;
  428. #endif /* stack grows upward */
  429.  
  430.   return sp;
  431. }
  432.  
  433. /* Push LEN bytes with data at BUFFER.  */
  434.  
  435. CORE_ADDR
  436. push_bytes (sp, buffer, len)
  437.      CORE_ADDR sp;
  438.      char *buffer;
  439.      int len;
  440. {
  441. #if 1 INNER_THAN 2
  442.   sp -= len;
  443.   write_memory (sp, buffer, len);
  444. #else /* stack grows upward */
  445.   write_memory (sp, buffer, len);
  446.   sp += len;
  447. #endif /* stack grows upward */
  448.  
  449.   return sp;
  450. }
  451.  
  452. /* Push onto the stack the specified value VALUE.  */
  453.  
  454. CORE_ADDR
  455. value_push (sp, arg)
  456.      register CORE_ADDR sp;
  457.      value arg;
  458. {
  459.   register int len = TYPE_LENGTH (VALUE_TYPE (arg));
  460.  
  461. #if 1 INNER_THAN 2
  462.   sp -= len;
  463.   write_memory (sp, VALUE_CONTENTS (arg), len);
  464. #else /* stack grows upward */
  465.   write_memory (sp, VALUE_CONTENTS (arg), len);
  466.   sp += len;
  467. #endif /* stack grows upward */
  468.  
  469.   return sp;
  470. }
  471.  
  472. /* Perform the standard coercions that are specified
  473.    for arguments to be passed to C functions.  */
  474.  
  475. value
  476. value_arg_coerce (arg)
  477.      value arg;
  478. {
  479.   register struct type *type;
  480.  
  481.   COERCE_ENUM (arg);
  482.  
  483.   type = VALUE_TYPE (arg);
  484.  
  485.   if (TYPE_CODE (type) == TYPE_CODE_INT
  486.       && TYPE_LENGTH (type) < sizeof (int))
  487.     return value_cast (builtin_type_int, arg);
  488.  
  489.   if (type == builtin_type_float)
  490.     return value_cast (builtin_type_double, arg);
  491.  
  492.   return arg;
  493. }
  494.  
  495. /* Push the value ARG, first coercing it as an argument
  496.    to a C function.  */
  497.  
  498. CORE_ADDR
  499. value_arg_push (sp, arg)
  500.      register CORE_ADDR sp;
  501.      value arg;
  502. {
  503.   return value_push (sp, value_arg_coerce (arg));
  504. }
  505.  
  506. /* Perform a function call in the inferior.
  507.    ARGS is a vector of values of arguments (NARGS of them).
  508.    FUNCTION is a value, the function to be called.
  509.    Returns a value representing what the function returned.
  510.    May fail to return, if a breakpoint or signal is hit
  511.    during the execution of the function.  */
  512.  
  513. value
  514. call_function (function, nargs, args)
  515.      value function;
  516.      int nargs;
  517.      value *args;
  518. {
  519.   register CORE_ADDR sp;
  520.   register int i;
  521.   CORE_ADDR start_sp;
  522.   static REGISTER_TYPE dummy[] = CALL_DUMMY;
  523.   REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)];
  524.   CORE_ADDR old_sp;
  525.   struct type *value_type;
  526.   unsigned char struct_return;
  527.   CORE_ADDR struct_addr;
  528.   struct inferior_status inf_status;
  529.   struct cleanup *old_chain;
  530.  
  531.   if (!have_inferior_p ())
  532.     error ("Cannot invoke functions if the inferior is not running.");
  533.  
  534. #ifndef KGDB  
  535.   save_inferior_status (&inf_status, 1);
  536.   old_chain = make_cleanup (restore_inferior_status, &inf_status);
  537.  
  538.   /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers
  539.      (and POP_FRAME for restoring them).  (At least on most machines)
  540.      they are saved on the stack in the inferior.  */
  541.   PUSH_DUMMY_FRAME;
  542.  
  543.   old_sp = sp = read_register (SP_REGNUM);
  544.  
  545. #if 1 INNER_THAN 2        /* Stack grows down */
  546.   sp -= sizeof dummy;
  547.   start_sp = sp;
  548. #else                /* Stack grows up */
  549.   start_sp = sp;
  550.   sp += sizeof dummy;
  551. #endif
  552. #endif
  553.  
  554.   {
  555.     register CORE_ADDR funaddr;
  556.     register struct type *ftype = VALUE_TYPE (function);
  557.     register enum type_code code = TYPE_CODE (ftype);
  558.  
  559.     /* If it's a member function, just look at the function
  560.        part of it.  */
  561.  
  562.     /* Determine address to call.  */
  563.     if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
  564.       {
  565.     funaddr = VALUE_ADDRESS (function);
  566.     value_type = TYPE_TARGET_TYPE (ftype);
  567.       }
  568.     else if (code == TYPE_CODE_PTR)
  569.       {
  570.     funaddr = value_as_long (function);
  571.     if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
  572.         || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
  573.       value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
  574.     else
  575.       value_type = builtin_type_int;
  576.       }
  577.     else if (code == TYPE_CODE_INT)
  578.       {
  579.     /* Handle the case of functions lacking debugging info.
  580.        Their values are characters since their addresses are char */
  581.     if (TYPE_LENGTH (ftype) == 1)
  582.       funaddr = value_as_long (value_addr (function));
  583.     else
  584.       /* Handle integer used as address of a function.  */
  585.       funaddr = value_as_long (function);
  586.  
  587.     value_type = builtin_type_int;
  588.       }
  589.     else
  590.       error ("Invalid data type for function to be called.");
  591. #ifdef KGDB
  592.  /* Create a call sequence customized for this function
  593.     and the number of arguments for it.  */
  594.    if (remote_debugging) {
  595.     int    val;
  596.     char argBuffer[512];
  597.     char *ap;
  598.     ap = argBuffer;
  599.     for (i = 0; i < nargs; i++) {
  600.             value arg = value_arg_coerce (args[i]);
  601.             int len = TYPE_LENGTH (VALUE_TYPE (arg));
  602.            if (ap + len > &(argBuffer[512]) )
  603.             break;
  604.            bcopy(VALUE_CONTENTS (arg),ap,len);
  605.            ap += len;
  606.     }
  607.     val = call_remote_function(funaddr,nargs,ap - argBuffer,argBuffer);
  608.     return value_from_long (builtin_type_int, val);
  609.    }
  610. #endif    
  611.  
  612.     /* Are we returning a value using a structure return or a normal
  613.        value return? */
  614.  
  615.     struct_return = using_struct_return (function, funaddr, value_type);
  616.  
  617.     /* Create a call sequence customized for this function
  618.        and the number of arguments for it.  */
  619.     bcopy (dummy, dummy1, sizeof dummy);
  620.     FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, value_type);
  621.   }
  622.  
  623. #ifndef CANNOT_EXECUTE_STACK
  624.   write_memory (start_sp, dummy1, sizeof dummy);
  625.  
  626. #else
  627.   /* Convex Unix prohibits executing in the stack segment. */
  628.   /* Hope there is empty room at the top of the text segment. */
  629.   {
  630.     extern CORE_ADDR text_end;
  631.     static checked = 0;
  632.     if (!checked)
  633.       for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp)
  634.     if (read_memory_integer (start_sp, 1) != 0)
  635.       error ("text segment full -- no place to put call");
  636.     checked = 1;
  637.     sp = old_sp;
  638.     start_sp = text_end - sizeof dummy;
  639.     write_memory (start_sp, dummy1, sizeof dummy);
  640.   }
  641. #endif /* CANNOT_EXECUTE_STACK */
  642. #ifdef STACK_ALIGN
  643.   /* If stack grows down, we must leave a hole at the top. */
  644.   {
  645.     int len = 0;
  646.  
  647.     /* Reserve space for the return structure to be written on the
  648.        stack, if necessary */
  649.  
  650.     if (struct_return)
  651.       len += TYPE_LENGTH (value_type);
  652.     
  653.     for (i = nargs - 1; i >= 0; i--)
  654.       len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));
  655. #ifdef CALL_DUMMY_STACK_ADJUST
  656.     len += CALL_DUMMY_STACK_ADJUST;
  657. #endif
  658. #if 1 INNER_THAN 2
  659.     sp -= STACK_ALIGN (len) - len;
  660. #else
  661.     sp += STACK_ALIGN (len) - len;
  662. #endif
  663.   }
  664. #endif /* STACK_ALIGN */
  665.  
  666.     /* Reserve space for the return structure to be written on the
  667.        stack, if necessary */
  668.  
  669.     if (struct_return)
  670.       {
  671. #if 1 INNER_THAN 2
  672.     sp -= TYPE_LENGTH (value_type);
  673.     struct_addr = sp;
  674. #else
  675.     struct_addr = sp;
  676.     sp += TYPE_LENGTH (value_type);
  677. #endif
  678.       }
  679.     
  680. #ifdef PUSH_ARGUMENTS
  681.   PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr);
  682. #else /* !PUSH_ARGUMENTS */
  683.   for (i = nargs - 1; i >= 0; i--)
  684.     sp = value_arg_push (sp, args[i]);
  685.  
  686. #ifdef CALL_DUMMY_STACK_ADJUST
  687. #if 1 INNER_THAN 2
  688.   sp -= CALL_DUMMY_STACK_ADJUST;
  689. #else
  690.   sp += CALL_DUMMY_STACK_ADJUST;
  691. #endif
  692. #endif /* CALL_DUMMY_STACK_ADJUST */
  693.  
  694.   /* Store the address at which the structure is supposed to be
  695.      written.  Note that this (and the code which reserved the space
  696.      above) assumes that gcc was used to compile this function.  Since
  697.      it doesn't cost us anything but space and if the function is pcc
  698.      it will ignore this value, we will make that assumption.
  699.  
  700.      Also note that on some machines (like the sparc) pcc uses this
  701.      convention in a slightly twisted way also.  */
  702.  
  703.   if (struct_return)
  704.     STORE_STRUCT_RETURN (struct_addr, sp);
  705. #endif /* !PUSH_ARGUMENTS */
  706.  
  707.   /* Write the stack pointer.  This is here because the statement above
  708.      might fool with it */
  709.   write_register (SP_REGNUM, sp);
  710.  
  711.   /* Figure out the value returned by the function.  */
  712.   {
  713.     char retbuf[REGISTER_BYTES];
  714.  
  715.     /* Execute the stack dummy routine, calling FUNCTION.
  716.        When it is done, discard the empty frame
  717.        after storing the contents of all regs into retbuf.  */
  718.     run_stack_dummy (start_sp + CALL_DUMMY_START_OFFSET, retbuf);
  719.  
  720.     do_cleanups (old_chain);
  721.  
  722.     return value_being_returned (value_type, retbuf, struct_return);
  723.   }
  724. }
  725.  
  726. /* Create a value for a string constant:
  727.    Call the function malloc in the inferior to get space for it,
  728.    then copy the data into that space
  729.    and then return the address with type char *.
  730.    PTR points to the string constant data; LEN is number of characters.  */
  731.  
  732. value
  733. value_string (ptr, len)
  734.      char *ptr;
  735.      int len;
  736. {
  737.   register value val;
  738.   register struct symbol *sym;
  739.   value blocklen;
  740.   register char *copy = (char *) alloca (len + 1);
  741.   char *i = ptr;
  742.   register char *o = copy, *ibeg = ptr;
  743.   register int c;
  744.  
  745.   /* Copy the string into COPY, processing escapes.
  746.      We could not conveniently process them in expread
  747.      because the string there wants to be a substring of the input.  */
  748.  
  749.   while (i - ibeg < len)
  750.     {
  751.       c = *i++;
  752.       if (c == '\\')
  753.     {
  754.       c = parse_escape (&i);
  755.       if (c == -1)
  756.         continue;
  757.     }
  758.       *o++ = c;
  759.     }
  760.   *o = 0;
  761.  
  762.   /* Get the length of the string after escapes are processed.  */
  763.  
  764.   len = o - copy;
  765.  
  766.   /* Find the address of malloc in the inferior.  */
  767.  
  768.   sym = lookup_symbol ("malloc", 0, VAR_NAMESPACE, 0);
  769.   if (sym != 0)
  770.     {
  771.       if (SYMBOL_CLASS (sym) != LOC_BLOCK)
  772.     error ("\"malloc\" exists in this program but is not a function.");
  773.       val = value_of_variable (sym);
  774.     }
  775.   else
  776.     {
  777.       register int i;
  778.       for (i = 0; i < misc_function_count; i++)
  779.     if (!strcmp (misc_function_vector[i].name, "malloc"))
  780.       break;
  781.       if (i < misc_function_count)
  782.     val = value_from_long (builtin_type_long,
  783.                  (LONGEST) misc_function_vector[i].address);
  784.       else
  785.     error ("String constants require the program to have a function \"malloc\".");
  786.     }
  787.  
  788.   blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1));
  789.   val = call_function (val, 1, &blocklen);
  790.   if (value_zerop (val))
  791.     error ("No memory available for string constant.");
  792.   write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1);
  793.   VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char);
  794.   return val;
  795. }
  796.  
  797. /* Given ARG1, a value of type (pointer to a)* structure/union,
  798.    extract the component named NAME from the ultimate target structure/union
  799.    and return it as a value with its appropriate type.
  800.    ERR is used in the error message if ARG1's type is wrong.
  801.  
  802.    C++: ARGS is a list of argument types to aid in the selection of
  803.    an appropriate method. Also, handle derived types.
  804.  
  805.    STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
  806.    where the truthvalue of whether the function that was resolved was
  807.    a static member function or not.
  808.  
  809.    ERR is an error message to be printed in case the field is not found.  */
  810.  
  811. value
  812. value_struct_elt (arg1, args, name, static_memfuncp, err)
  813.      register value arg1, *args;
  814.      char *name;
  815.      int *static_memfuncp;
  816.      char *err;
  817. {
  818.   register struct type *t;
  819.   register int i;
  820.   int found = 0;
  821.  
  822.   struct type *baseclass;
  823.  
  824.   COERCE_ARRAY (arg1);
  825.  
  826.   t = VALUE_TYPE (arg1);
  827.  
  828.   /* Follow pointers until we get to a non-pointer.  */
  829.  
  830.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  831.     {
  832.       arg1 = value_ind (arg1);
  833.       COERCE_ARRAY (arg1);
  834.       t = VALUE_TYPE (arg1);
  835.     }
  836.  
  837.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  838.     error ("not implemented: member type in value_struct_elt");
  839.  
  840.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  841.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  842.     error ("Attempt to extract a component of a value that is not a %s.", err);
  843.  
  844.   baseclass = t;
  845.  
  846.   /* Assume it's not, unless we see that it is.  */
  847.   if (static_memfuncp)
  848.     *static_memfuncp =0;
  849.  
  850.   if (!args)
  851.     {
  852.       /* if there are no arguments ...do this...  */
  853.  
  854.       /* Try as a variable first, because if we succeed, there
  855.      is less work to be done.  */
  856.       while (t)
  857.     {
  858.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  859.         {
  860.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  861.           if (t_field_name && !strcmp (t_field_name, name))
  862.         {
  863.           found = 1;
  864.           break;
  865.         }
  866.         }
  867.  
  868.       if (i >= 0)
  869.         return TYPE_FIELD_STATIC (t, i)
  870.           ? value_static_field (t, name, i) : value_field (arg1, i);
  871.  
  872.       if (TYPE_N_BASECLASSES (t) == 0)
  873.         break;
  874.  
  875.       t = TYPE_BASECLASS (t, 1);
  876.       VALUE_TYPE (arg1) = t; /* side effect! */
  877.     }
  878.  
  879.       /* C++: If it was not found as a data field, then try to
  880.          return it as a pointer to a method.  */
  881.       t = baseclass;
  882.       VALUE_TYPE (arg1) = t;    /* side effect! */
  883.  
  884.       if (destructor_name_p (name, t))
  885.     error ("use `info method' command to print out value of destructor");
  886.  
  887.       while (t)
  888.     {
  889.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  890.         {
  891.           if (! strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  892.         {
  893.           error ("use `info method' command to print value of method \"%s\"", name);
  894.         }
  895.         }
  896.  
  897.       if (TYPE_N_BASECLASSES (t) == 0)
  898.         break;
  899.  
  900.       t = TYPE_BASECLASS (t, 1);
  901.     }
  902.  
  903.       if (found == 0)
  904.     error ("There is no field named %s.", name);
  905.       return 0;
  906.     }
  907.  
  908.   if (destructor_name_p (name, t))
  909.     {
  910.       if (!args[1])
  911.     {
  912.       /* destructors are a special case.  */
  913.       return (value)value_fn_field (arg1, 0,
  914.                     TYPE_FN_FIELDLIST_LENGTH (t, 0));
  915.     }
  916.       else
  917.     {
  918.       error ("destructor should not have any argument");
  919.     }
  920.     }
  921.  
  922.   /*   This following loop is for methods with arguments.  */
  923.   while (t)
  924.     {
  925.       /* Look up as method first, because that is where we
  926.      expect to find it first.  */
  927.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; i--)
  928.     {
  929.       struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  930.  
  931.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  932.         {
  933.           int j;
  934.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  935.  
  936.           found = 1;
  937.           for (j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1; j >= 0; --j)
  938.         if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
  939.                   TYPE_FN_FIELD_ARGS (f, j), args))
  940.           {
  941.             if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  942.               return (value)value_virtual_fn_field (arg1, f, j, t);
  943.             if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
  944.               *static_memfuncp = 1;
  945.             return (value)value_fn_field (arg1, i, j);
  946.           }
  947.         }
  948.     }
  949.  
  950.       if (TYPE_N_BASECLASSES (t) == 0)
  951.     break;
  952.       
  953.       t = TYPE_BASECLASS (t, 1);
  954.       VALUE_TYPE (arg1) = t;    /* side effect! */
  955.     }
  956.  
  957.   if (found)
  958.     {
  959.       error ("Structure method %s not defined for arglist.", name);
  960.       return 0;
  961.     }
  962.   else
  963.     {
  964.       /* See if user tried to invoke data as function */
  965.       t = baseclass;
  966.       while (t)
  967.     {
  968.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  969.         {
  970.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  971.           if (t_field_name && !strcmp (t_field_name, name))
  972.         {
  973.           found = 1;
  974.           break;
  975.         }
  976.         }
  977.  
  978.       if (i >= 0)
  979.         return TYPE_FIELD_STATIC (t, i)
  980.           ? value_static_field (t, name, i) : value_field (arg1, i);
  981.  
  982.       if (TYPE_N_BASECLASSES (t) == 0)
  983.         break;
  984.  
  985.       t = TYPE_BASECLASS (t, 1);
  986.       VALUE_TYPE (arg1) = t; /* side effect! */
  987.     }
  988.       error ("Structure has no component named %s.", name);
  989.     }
  990. }
  991.  
  992. /* C++: return 1 is NAME is a legitimate name for the destructor
  993.    of type TYPE.  If TYPE does not have a destructor, or
  994.    if NAME is inappropriate for TYPE, an error is signaled.  */
  995. int
  996. destructor_name_p (name, type)
  997.      char *name;
  998.      struct type *type;
  999. {
  1000.   /* destructors are a special case.  */
  1001.   char *dname = TYPE_NAME (type);
  1002.  
  1003.   if (name[0] == '~')
  1004.     {
  1005.       if (! TYPE_HAS_DESTRUCTOR (type))
  1006.     error ("type `%s' does not have destructor defined",
  1007.            TYPE_NAME (type));
  1008.       /* Skip past the "struct " at the front.  */
  1009.       while (*dname++ != ' ') ;
  1010.       if (strcmp (dname, name+1))
  1011.     error ("destructor specification error");
  1012.       else
  1013.     return 1;
  1014.     }
  1015.   return 0;
  1016. }
  1017.  
  1018. /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
  1019.    return 1 if the component named NAME from the ultimate
  1020.    target structure/union is defined, otherwise, return 0.  */
  1021.  
  1022. int
  1023. check_field (arg1, name)
  1024.      register value arg1;
  1025.      char *name;
  1026. {
  1027.   register struct type *t;
  1028.   register int i;
  1029.   int found = 0;
  1030.  
  1031.   struct type *baseclass;
  1032.  
  1033.   COERCE_ARRAY (arg1);
  1034.  
  1035.   t = VALUE_TYPE (arg1);
  1036.  
  1037.   /* Follow pointers until we get to a non-pointer.  */
  1038.  
  1039.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  1040.     t = TYPE_TARGET_TYPE (t);
  1041.  
  1042.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  1043.     error ("not implemented: member type in check_field");
  1044.  
  1045.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1046.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1047.     error ("Internal error: `this' is not an aggregate");
  1048.  
  1049.   baseclass = t;
  1050.  
  1051.   while (t)
  1052.     {
  1053.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1054.     {
  1055.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1056.       if (t_field_name && !strcmp (t_field_name, name))
  1057.         {
  1058.           return 1;
  1059.         }
  1060.     }
  1061.       if (TYPE_N_BASECLASSES (t) == 0)
  1062.     break;
  1063.  
  1064.       t = TYPE_BASECLASS (t, 1);
  1065.     }
  1066.  
  1067.   /* C++: If it was not found as a data field, then try to
  1068.      return it as a pointer to a method.  */
  1069.   t = baseclass;
  1070.   VALUE_TYPE (arg1) = t;    /* side effect! */
  1071.  
  1072.   /* Destructors are a special case.  */
  1073.   if (destructor_name_p (name, t))
  1074.     return 1;
  1075.  
  1076.   while (t)
  1077.     {
  1078.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1079.     {
  1080.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1081.         return 1;
  1082.     }
  1083.  
  1084.       if (TYPE_N_BASECLASSES (t) == 0)
  1085.     break;
  1086.  
  1087.       t = TYPE_BASECLASS (t, 1);
  1088.     }
  1089.   return 0;
  1090. }
  1091.  
  1092. /* C++: Given an aggregate type DOMAIN, and a member name NAME,
  1093.    return the address of this member as a pointer to member
  1094.    type.  If INTYPE is non-null, then it will be the type
  1095.    of the member we are looking for.  This will help us resolve
  1096.    pointers to member functions.  */
  1097.  
  1098. value
  1099. value_struct_elt_for_address (domain, intype, name)
  1100.      struct type *domain, *intype;
  1101.      char *name;
  1102. {
  1103.   register struct type *t = domain;
  1104.   register int i;
  1105.   int found = 0;
  1106.   value v;
  1107.  
  1108.   struct type *baseclass;
  1109.  
  1110.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1111.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1112.     error ("Internal error: non-aggregate type to value_struct_elt_for_address");
  1113.  
  1114.   baseclass = t;
  1115.  
  1116.   while (t)
  1117.     {
  1118.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1119.     {
  1120.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1121.       if (t_field_name && !strcmp (t_field_name, name))
  1122.         {
  1123.           if (TYPE_FIELD_PACKED (t, i))
  1124.         error ("pointers to bitfield members not allowed");
  1125.  
  1126.           v = value_from_long (builtin_type_int,
  1127.                    (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
  1128.           VALUE_TYPE (v) = lookup_pointer_type (
  1129.               lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass));
  1130.           return v;
  1131.         }
  1132.     }
  1133.  
  1134.       if (TYPE_N_BASECLASSES (t) == 0)
  1135.     break;
  1136.  
  1137.       t = TYPE_BASECLASS (t, 1);
  1138.     }
  1139.  
  1140.   /* C++: If it was not found as a data field, then try to
  1141.      return it as a pointer to a method.  */
  1142.   t = baseclass;
  1143.  
  1144.   /* Destructors are a special case.  */
  1145.   if (destructor_name_p (name, t))
  1146.     {
  1147.       error ("pointers to destructors not implemented yet");
  1148.     }
  1149.  
  1150.   /* Perform all necessary dereferencing.  */
  1151.   while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
  1152.     intype = TYPE_TARGET_TYPE (intype);
  1153.  
  1154.   while (t)
  1155.     {
  1156.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1157.     {
  1158.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1159.         {
  1160.           int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
  1161.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  1162.  
  1163.           if (intype == 0 && j > 1)
  1164.         error ("non-unique member `%s' requires type instantiation", name);
  1165.           if (intype)
  1166.         {
  1167.           while (j--)
  1168.             if (TYPE_FN_FIELD_TYPE (f, j) == intype)
  1169.               break;
  1170.           if (j < 0)
  1171.             error ("no member function matches that type instantiation");
  1172.         }
  1173.           else
  1174.         j = 0;
  1175.  
  1176.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1177.         {
  1178.           v = value_from_long (builtin_type_long,
  1179.                        (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
  1180.         }
  1181.           else
  1182.         {
  1183.           struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
  1184.                             0, VAR_NAMESPACE, 0);
  1185.           v = locate_var_value (s, 0);
  1186.         }
  1187.           VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
  1188.           return v;
  1189.         }
  1190.     }
  1191.  
  1192.       if (TYPE_N_BASECLASSES (t) == 0)
  1193.     break;
  1194.  
  1195.       t = TYPE_BASECLASS (t, 1);
  1196.     }
  1197.   return 0;
  1198. }
  1199.  
  1200. /* Compare two argument lists and return the position in which they differ,
  1201.    or zero if equal.
  1202.  
  1203.    STATICP is nonzero if the T1 argument list came from a
  1204.    static member function.
  1205.  
  1206.    For non-static member functions, we ignore the first argument,
  1207.    which is the type of the instance variable.  This is because we want
  1208.    to handle calls with objects from derived classes.  This is not
  1209.    entirely correct: we should actually check to make sure that a
  1210.    requested operation is type secure, shouldn't we?  */
  1211.  
  1212. int
  1213. typecmp (staticp, t1, t2)
  1214.      int staticp;
  1215.      struct type *t1[];
  1216.      value t2[];
  1217. {
  1218.   int i;
  1219.  
  1220.   if (staticp && t1 == 0)
  1221.     return t2[1] != 0;
  1222.   if (t1 == 0)
  1223.     return 1;
  1224.   if (t1[0]->code == TYPE_CODE_VOID) return 0;
  1225.   if (t1[!staticp] == 0) return 0;
  1226.   for (i = !staticp; t1[i] && t1[i]->code != TYPE_CODE_VOID; i++)
  1227.     {
  1228.       if (! t2[i]
  1229.       || t1[i]->code != t2[i]->type->code
  1230.       || t1[i]->target_type != t2[i]->type->target_type)
  1231.     return i+1;
  1232.     }
  1233.   if (!t1[i]) return 0;
  1234.   return t2[i] ? i+1 : 0;
  1235. }
  1236.  
  1237. /* C++: return the value of the class instance variable, if one exists.
  1238.    Flag COMPLAIN signals an error if the request is made in an
  1239.    inappropriate context.  */
  1240. value
  1241. value_of_this (complain)
  1242.      int complain;
  1243. {
  1244.   extern FRAME selected_frame;
  1245.   struct symbol *func, *sym;
  1246.   char *funname = 0;
  1247.   struct block *b;
  1248.   int i;
  1249.  
  1250.   if (selected_frame == 0)
  1251.     if (complain)
  1252.       error ("no frame selected");
  1253.     else return 0;
  1254.  
  1255.   func = get_frame_function (selected_frame);
  1256.   if (func)
  1257.     funname = SYMBOL_NAME (func);
  1258.   else
  1259.     if (complain)
  1260.       error ("no `this' in nameless context");
  1261.     else return 0;
  1262.  
  1263.   b = SYMBOL_BLOCK_VALUE (func);
  1264.   i = BLOCK_NSYMS (b);
  1265.   if (i <= 0)
  1266.     if (complain)
  1267.       error ("no args, no `this'");
  1268.     else return 0;
  1269.  
  1270.   sym = BLOCK_SYM (b, 0);
  1271.   if (strncmp ("$this", SYMBOL_NAME (sym), 5))
  1272.     if (complain)
  1273.       error ("current stack frame not in method");
  1274.     else return 0;
  1275.  
  1276.   return read_var_value (sym, selected_frame);
  1277. }
  1278.